// 6.54 假设以顺序表sa表示一棵完全二叉树，sa.elem[1..sa.last]中存放树中各结点的数据元素。试编写算法由此顺序存储结构建立该二叉树的二叉链表。

#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"

void fun_6_54_1(tree *&root, int a[], int n, int index)
{
    if (index <= n)
    {
        root = (tree *)malloc(sizeof(tree));
        root->data = a[index];
        root->left = root->right = NULL;
        fun_6_54_1(root->left, a, n, 2 * index + 1);
        fun_6_54_1(root->right, a, n, 2 * index + 2);
    }
}

void fun_6_54(int a[], int n, tree *&root)
{
    fun_6_54_1(root, a, n, 0);
}

int main()
{
    /*******************code*******************/
    int n = 11;
    int a1[11] = {1,
                  2, 3,
                  4, 5, 6, 7,
                  8, 9, 10, 11};
    tree *root;
    fun_6_54(a1, n, root);
    /******************************************/
    printf("\n\n****************************\n");
    printf("Press Enter key to continue\n");
    getchar();
    return 0;
    /******************************************/
}
